import {Service} from "adajs";
import User from "./../../../lib/user";

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                bq: "住院病情",
                ltzInfo: {
                    xm: "刘琼"
                },
                crtIp: "39.155.166.62",
                crtTime: "2018-12-17 14:31:30",
                crtUser: "admin",
                cysj: "2018-12-16 00:00:00",
                id: "e69910c9-f2f6-43cf-8c0a-d5537220278d",
                ksbc: "科室病床",
                ltzid: "e17444ce-f135-4c45-8ceb-31669ba12869",
                phr: "陪护人",
                phrdh: "13211111111",
                rysj: "2018-12-10 00:00:00",
                sfcy: "6263bb00-33dc-49e1-842f-b9b694b4694c",
                sfkw: "0",
                updIp: "39.155.166.62",
                updTime: "2018-12-17 14:36:41",
                updUser: "admin",
                wkwyy: "治疗结果",
                yiyuan: "北京医院",
                zljg: "为看望原因"
            },
            id: "",
            error: false,
            msg: ''
        };
    }

    onupdate(current, id) {
        if (id) {
            if (User.isAdmin()) {
                return this.context.request.post("/api/lgb/app/lgb/hospitalization/getHosInfo", {id}).then(({code, data, msg}) => {
                    current.isLoad = true;
                    current.id = id;
                    if (code === '1') {
                        current.error=false;
                        current.newsInfo = data;
                        current.newsInfo.state = data.sfkw == '0' ? '是' : '否';
                    } else {
                        current.error = true;
                        current.msg = msg;
                    }
                });
            } else {
                return this.context.request.post("/api/lgb/app/lgb/hospitalization/getHosInfo", {id}).then(({code, data, msg}) => {
                    current.id = id;
                    current.isLoad = true;
                    if (code === '1') {
                        current.error=false;
                        current.newsInfo = data;
                        current.newsInfo.state = data.sfkw == '0' ? '是' : '否';
                    } else {
                        current.error = true;
                        current.msg = msg;
                    }
                });
            }
        }
    }
}

export default NewsService;